package com.layer.cms.controller.${modular};

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson2.JSON;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.layer.cms.common.result.ResponseData;
import ${packageName}.service.${className}Service;
import ${packageName}.dto.${className}Dto;
import ${packageName}.vo.${className}Vo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(tags = "${remark}, 前端控制器")
@ApiSupport(author = "${operationSupport}")
@RestController
@RequestMapping("/${modular}/${className?uncap_first}")
public class ${className}Controller {

	@Autowired
	private ${className}Service ${className?uncap_first}Service;
	
	@ApiOperation("条件查询")
	@ApiOperationSupport(author = "${operationSupport}")
	@PostMapping("/list")
	public ResponseData<List<${className}Vo>> list(@RequestBody ${className}Dto dto) {

		return ${className?uncap_first}Service.list(dto);
	}

	@ApiOperation("添加或者修改")
	@ApiOperationSupport(author = "${operationSupport}")
	@PostMapping("/saveOrUpdate")
	public ResponseData<String> saveOrUpdate(@RequestBody ${className}Dto dto) {
		return ${className?uncap_first}Service.insertOrUpdate(dto);
	}

	@ApiOperation("查询详情")
	@ApiOperationSupport(author = "${operationSupport}")
	@ApiImplicitParam(name = "id", value = "用户ID")
	@PostMapping("/findById")
	public ResponseData<${className}Vo> findById(@RequestBody String json) {
		return ${className?uncap_first}Service.queryById(JSON.parseObject(json).getString("id"));
	}
	
	@ApiOperation("禁用或启用")
	@ApiOperationSupport(author = "${operationSupport}")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "id", value = "ID"),
		@ApiImplicitParam(name = "state", value = "状态;true:开启; false: 禁用"),
	})
	@PostMapping("/state")
	public ResponseData<String> state(@RequestBody String json) {
		return ${className?uncap_first}Service.state(JSON.parseObject(json).getString("id"), JSON.parseObject(json).getBoolean("state"));
	}
	
	@ApiOperation("单个删除")
	@ApiOperationSupport(author = "${operationSupport}")
	@ApiImplicitParam(name = "id", value = "ID", required = true)
	@PostMapping("/delete")
	public ResponseData<String> delete(@RequestBody String json) {
		return ${className?uncap_first}Service.delete(JSON.parseObject(json).getString("id"));
	}
	
	@ApiOperation("批量删除")
	@ApiOperationSupport(author = "${operationSupport}")
	@PostMapping("/batchDelete")
	public ResponseData<String> batchDelete(@RequestBody List<${className}Dto> list) {
		return ${className?uncap_first}Service.batchDelete(list);
	}
	
	@ApiOperation("批量启用")
	@ApiOperationSupport(author = "${operationSupport}")
	@PostMapping("/online")
	public ResponseData<String> online(@RequestBody List<${className}Dto> list) {
		return ${className?uncap_first}Service.online(list);
	}
	
	@PostMapping("/offline")
	@ApiOperation("批量禁用")
	@ApiOperationSupport(author = "${operationSupport}")
	public ResponseData<String> offline(@RequestBody List<${className}Dto> list) {
		return ${className?uncap_first}Service.offline(list);
	}
	
//	@ApiOperation("清空表数据")
//	@ApiOperationSupport(author = "大象")
//	@PostMapping("/deleteAll")
//	public ResponseData<String> deleteAll() {
//		return userService.deleteAll();
//	}
}
